package View;


import java.io.File;
import java.io.FileNotFoundException;

import javax.swing.JFileChooser;
import javax.swing.filechooser.FileFilter;

public class OpenDialog {

	private MyView main;
	
	public OpenDialog(MyView main) {
		this.main = main;
	}
	
	public void show() {
		//Create a file chooser
		final JFileChooser fc = new JFileChooser(new File("."));
		FileFilter filter = new FileFilter() {
			
			@Override
			public String getDescription() {
				// TODO Auto-generated method stub				
				return "*.sql";
			}
			
			@Override
			public boolean accept(File f) {
				// TODO Auto-generated method stub
				if(f.isDirectory() || f.getName().endsWith(".sql")){
					return true;
				}
				return false;
			}
		};
		fc.setFileFilter(filter);
		fc.setAcceptAllFileFilterUsed(false);
		//In response to a button click:
		int returnVal = fc.showOpenDialog(main.getFrame());
		
		File file = fc.getSelectedFile();
		
		try {
			((MainView)main).loadSQLFromFile(file.getAbsolutePath());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}

